package com.ruoyi.jpbi.controller.organization;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.jpbi.domain.konggu.*;
import com.ruoyi.jpbi.service.CompanysService;
import com.ruoyi.jpbi.service.DepartmentsService;
import com.ruoyi.jpbi.service.EmpsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("/neworgs")
public class OrgsNewController extends BaseController {
    @Autowired
    private CompanysService companysService;

    @Autowired
    private DepartmentsService departmentsService;

    @Autowired
    private EmpsService empsService;

    private String prefix = "jpbi/organization/neworgs";


    /**
     * 跳转分页页面
     */
    @GetMapping()
    public String user() {
        return prefix + "/neworgs";
    }

    /**
     * 跳转到人员列表页面，带入公司或者部门的ID
     */
    @RequestMapping("/toPerson")
    public String toPerson(String id, ModelMap mmap) {
        mmap.put("id", id);
        return prefix + "/personList";
    }

    /**
     * 获取公司或部门的所属人员
     *
     * @param id   员工ID
     * @param emps 条件查询对象
     */
    @RequestMapping("/getPersonList")
    @ResponseBody
    public TableDataInfo getPersonList(int id, Emps emps) {
        startPage();
        String type = new String();
        if (id > 10000 && id <= 30000) {
            type = "comp";
            id -= 10000;
        } else if (id > 30000) {
            type = "dep";
            id -= 30000;
        }
        List<Emps> empsList = empsService.findPersonList(id + "", type, emps);
        return getDataTable(empsList);
    }

    @RequestMapping("detail")
    public String detail(String id, ModelMap mmap) {
        Emps jUser = empsService.findEmpone(id);
        if (jUser.getSiling() != 0) {
            jUser.setSiling(Math.ceil(jUser.getSiling()));//司龄向上取整
        }
        mmap.put("jUser", jUser);

        return prefix + "/details";
    }


    /**
     * 获取员工的教育经历
     *
     * @param eid 员工ID
     */
    @PostMapping("/EducationList")
    @ResponseBody
    public TableDataInfo EducationList(String eid) {
        List<Education> list = empsService.findEducations(Long.parseLong(eid));
        return getDataTable(list);
    }

    /**
     * 获取员工的工作经历
     *
     * @param eid 员工ID
     */
    @PostMapping("/WorkingList")
    @ResponseBody
    public TableDataInfo WorkingList(String eid) {
        List<Working> list = empsService.findWorkings(Long.parseLong(eid));
        return getDataTable(list);
    }

    /**
     * 获取员工的证书信息
     *
     * @param eid 员工ID
     */
    @PostMapping("/QualificationList")
    @ResponseBody
    public TableDataInfo QualificationList(String eid) {
        List<Qualification> list = empsService.findQualifications(Long.parseLong(eid));
        return getDataTable(list);
    }

    /**
     * 获取员工的语言能力
     *
     * @param eid 员工ID
     */
    @PostMapping("/LanguageList")
    @ResponseBody
    public TableDataInfo LanguageList(String eid) {
        List<Laguages> list = empsService.findLaguages(Long.parseLong(eid));
        return getDataTable(list);
    }

    /**
     * 获取员工的入职信息
     *
     * @param eid  员工ID
     * @param type 类型 Entry:入职  Becomefull:转正  change:变动   All:所有
     */
    @PostMapping("/EeventList")
    @ResponseBody
    public TableDataInfo EeventList(String eid, String type) {
        List<Events> list = null;
        if (eid == null) {
            list = empsService.findEvents(Long.parseLong("-1"), type);
        } else {
            list = empsService.findEvents(Long.parseLong(eid), type);
        }

        return getDataTable(list);
    }



}
